import requests
from pythonProject3.api import ihrm_login
from pythonProject3.tool import common
class emplyoee():
    def __init__(self):
        self.session=requests.session()
        self.emp_url=common.BASE_URL+"/api/sys/user"
        self.emp_puturl=common.BASE_URL+"/api/sys/user/{}"
        self.login=ihrm_login.login_basedata()
        # self.token=self.gettoken()
        token=self.gettoken()
        global headres_data
        common.headres_data["Authorization"]=token
        headres_data=common.headres_data

    def gettoken(self):
        response=self.login.login(self.session,"13800000002","123456")
        global token
        token=response.json().get("data")
        return token

    def emp_add(self,username,mobile,workNumber):
        data={
            "username":username,
            "mobile":mobile,
            "workNumber":workNumber
        }
        return requests.post(url=self.emp_url,headers=headres_data,json=data)

    def emp_update(self,empid,data):

        return requests.put(url=self.emp_puturl.format(empid),headers=headres_data,json=data)

    def emp_select(self,empid):

        return requests.get(url=self.emp_puturl.format(empid),headers=headres_data)

    def emp_del(self,empid):

        return requests.delete(url=self.emp_puturl.format(empid),headers=headres_data)


